package com.jr.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jr.mapper.PaymentsVehiclesParkingRecordsMapper;
import com.jr.service.PaymentsVehiclesParkingRecordsService;
import com.jr.vo.PaymentsVehiclesParkingRecordsVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 支付记录、车辆和停车记录关联查询服务实现类
 */
@Service
public class PaymentsVehiclesParkingRecordsServiceImpl implements PaymentsVehiclesParkingRecordsService {

    @Resource
    private PaymentsVehiclesParkingRecordsMapper paymentsVehiclesParkingRecordsMapper;

    @Override
    public PageInfo<PaymentsVehiclesParkingRecordsVo> findPaymentsByPage(
            Integer pageNum,
            Integer pageSize,
            String plateNumber,
            Integer status,
            String entryTime,
            String exitTime) {

        // 设置默认页码和每页条数
        if (pageNum == null || pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null || pageSize <= 0) {
            pageSize = 8; // 默认一页展示8条数据
        }

        // 使用PageHelper进行分页
        PageHelper.startPage(pageNum, pageSize);

        // 调用Mapper方法查询数据
        List<PaymentsVehiclesParkingRecordsVo> list = paymentsVehiclesParkingRecordsMapper.findPaymentsByPage(
                plateNumber,
                status,
                entryTime,
                exitTime
        );

        // 创建PageInfo对象
        return new PageInfo<>(list);
    }
}